<template>
  <!-- 小模块公共组件 -->
  <div class="Mould-Box">
    <!-- 图表 -->
    <div class="Mould-Box-chartBox">
      <div class="content-bottom">
        <div class="bottom-left">
          <RoseChart :data="cateLists" :color="color" />
        </div>
        <div class="bottom-right">
          <div class="legend">
            <Legend1
              v-for="(item, idx) in cateLists"
              :key="item.x"
              class="item"
              :name="item.x"
              :num="item.y"
              :color="color[idx]"
              unit=""
            ></Legend1>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import RoseChart from '@/components/chart/pie/RoseChart.vue';
import Legend1 from '@/components/chart/legend/Legend1.vue';
export default {
  components: {
    RoseChart,
    Legend1
  },
  props: {
    // 模块数据
    datas: {
      type: Array,
      required: true
    },
    text: {
      type: Array,
      required: true
    },
    chartOption: {
      type: Object,
      default: () => {}
    },
    chartTitle: {
      type: String,
      default: ''
    },
    color: {
      type: Array,
      default: () => ['#34C8FF', '#FFD101', '#57FFAA', '#00FDFF', '#1ED9FF']
    },
    orderKeys: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {};
  },
  computed: {
    cateLists() {
      return this.formatChartData(this.orderKeys, this.datas);
    }
  },
  methods: {
    // 调整图表数据格式，以及数据元素的排列顺序
    formatChartData(orderKeys, origin) {
      return orderKeys.map((orderKey) => {
        for (const item of origin) {
          if (orderKey === item.level1Desc) {
            return {
              x: item.level1Desc,
              y: item.alarmCount
            };
          }
        }
        return {
          x: orderKey,
          y: 0
        };
      });
    }
  }
};
</script>

<style lang='scss' scoped>
.Mould-Box {
  width: 20.625rem;
  &-chartBox {
    width: 100%;
    // height: 10.125rem;
  }
  .content-bottom {
    width: 20.625rem;
    height: 8.875rem;
    display: flex;
    .bottom-left {
      width: 8.875rem;
      height: 8.875rem;
      margin-right: 0.9375rem;
    }
    .bottom-right {
      flex: 1;
      width: 100%;
      .legend {
        height: 100%;
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        .item {
          width: 3.75rem;
        }
      }
    }
  }
}
</style>
